package com.eks.plus.service.impl;

import com.eks.plus.entity.CiCinema;
import com.eks.plus.mapper.CiCinemaMapper;
import com.eks.plus.service.ICiCinemaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eks.plus.query.CiCinemaQueryBo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 影院表  服务实现类
 * </p>
 *
 * @author chenfh
 * @since 2021-01-07
 */
@Service
public class CiCinemaServiceImpl extends ServiceImpl<CiCinemaMapper, CiCinema> implements ICiCinemaService {

    /**
     * 按照条件分页查询
     * @param query
     */
    @Override
    public IPage<CiCinema> page(CiCinemaQueryBo query,int pageNo,int pageSize){
        if(query==null){
            return new Page<>();
        }
        IPage<CiCinema> page = new Page<>();
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        QueryWrapper<CiCinema> queryWrapper = query.buildQuery();
        return this.page(page, queryWrapper);
    }

    @Override
    public CiCinema getOne(CiCinemaQueryBo query) {
        QueryWrapper<CiCinema> queryWrapper = query.buildQuery();
        return this.getOne(queryWrapper);
    }

    @Override
    public IPage<CiCinema> page(QueryWrapper<CiCinema> queryWrapper, int pageNo, int pageSize) {
        if(queryWrapper==null){
            return new Page<>();
        }
        IPage<CiCinema> page = new Page<>();
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        return this.page(page, queryWrapper);
    }

    @Override
    public boolean update(CiCinema entity,CiCinemaQueryBo query) {
        if(entity==null || query==null){
            return false;
        }
        return this.update(entity,query.buildQuery());
    }

    @Override
    public boolean updateByColumn(CiCinema entity, String column, Object value) {
        QueryWrapper<CiCinema> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(column,value);
        return this.update(entity, queryWrapper);
    }

    @Override
    public List<CiCinema> list(CiCinemaQueryBo query) {
        if(query==null){
            return new ArrayList<>(2);
        }
        return this.list(query.buildQuery());
    }

}
